package ${package.Controller};

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import ${package.ServiceImpl}.${table.serviceImplName};
import ${package.Entity}.${entity};
import com.ljd.common.datasource.server.component.base.BaseController;
import com.ljd.common.base.server.model.RestResult;
import com.ljd.common.base.server.model.BasePageDTO;
import com.ljd.common.core.server.model.result.PageResult;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>

<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>


/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if swagger>
@Api(tags = "${table.comment!}接口")
</#if>
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} extends BaseController<${table.serviceImplName}> {

    @ApiOperation(value = "添加")
    @PostMapping("")
    public RestResult<${entity}> add(@RequestBody ${entity} dto) {
        return service.add(dto);
    }

    @ApiOperation(value = "编辑")
    @PutMapping("")
    public RestResult<${entity}> edit(@RequestBody ${entity} dto) {
        return service.edit(dto);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public RestResult<String> delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping("paging")
    public RestResult<PageResult<${entity}>> paging(@RequestBody BasePageDTO dto){
        IPage<${entity}> pageList = service.pageList(dto);
        return RestResult.success(PageResult.startPage(pageList));
    }
</#if>

}
</#if>
